package mest.controller.hws;

import com.alibaba.fastjson.JSON;
import mest.entity.warehouse_file;
import mest.service.hws.WarehouseFilehwsService;
import mest.service.system.DBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;


/*
* 仓库档案
* */
@RestController
@RequestMapping("/WarehouseFileController")
@CrossOrigin
public class WarehouseFileController {

    @Resource
    private WarehouseFilehwsService warehouseFileService;
    @Autowired
    private DBService dbService;
/*    @Resource
    private ModelingDictionariesService modelingDictionariesService;*/



    //查询所有仓库档案
    @RequestMapping("/selectAll")
    public String selectPrimary(Integer limit,Integer page,String wfname){
        System.out.println("查询所有仓库档案");
        String theirDb = dbService.getCompanyDB();
        System.out.println(wfname);
        Map<Object,Object> map = new HashMap<Object,Object>();
        map.put("code",0);
        map.put("msg","success");
        map.put("count",warehouseFileService.selectcount(theirDb,wfname));
        map.put("data",warehouseFileService.selectPrimary(theirDb,limit,(page-1)*limit,wfname));
        return JSON.toJSONString(map);
    }

    //根据id查询仓库档案
    @RequestMapping("/selectById")
    public String selectByPrimaryKey(Integer id){
        System.out.println("根据id查询仓库档案");
        String theirDb = dbService.getCompanyDB();
        Map<Object,Object> map = new HashMap<Object,Object>();
        map.put("code",0);
        map.put("msg","success");
        map.put("count","count");
        map.put("data",warehouseFileService.selectByPrimaryKey(theirDb,id));
        return JSON.toJSONString(map);
    }

    //新增仓库档案
    @RequestMapping("/insertModel")
    public String insert(@RequestBody warehouse_file warehouseFile){
        System.out.println("新增仓库档案");
        String theirDb = dbService.getCompanyDB();
        Map<String, Object> map = new HashMap<String, Object>();
        return warehouseFileService.insert(theirDb,warehouseFile);
    }


    //更新仓库档案
    @RequestMapping("/updateByone")
    public String updateByPrimaryKey(@RequestBody warehouse_file warehouseFile){
        System.out.println("更新仓库档案");
        String theirDb = dbService.getCompanyDB();
        Map<String, Object> map = new HashMap<String, Object>();
        return warehouseFileService.updateByPrimaryKey(theirDb,warehouseFile);
    }

    //删除仓库档案
    @RequestMapping("/delModel")
    public String deleteByPrimaryKey(Integer id){
        System.out.println("删除仓库档案");
        String theirDb = dbService.getCompanyDB();
        Map<String, Object> map = new HashMap<String, Object>();
        int num = warehouseFileService.deleteByPrimaryKey(theirDb,id);
        if (num > 0) {
            map.put("code", 0);
            map.put("msg", "操作成功");
        } else {
            map.put("code", 1);
            map.put("msg", "操作失败");
        }
        return JSON.toJSONString(map);
    }

   /* //设备档案编码生成
    @RequestMapping("/Number")
    public String Number(){
        System.out.println("仓库档案编码生成");
        Map<Object,Object> map = new HashMap<Object,Object>();
        map.put("code",0);
        map.put("msg","success");
        map.put("count","count");
        map.put("data","CK-"+modelingDictionariesService.selectModelingDictionaries().getWarehouseNo());
        return JSON.toJSONString(map);

    }*/
}
